program q124;
var
    ans, i, value: longint;
    buf: string;
begin
    assign(input, '');
    assign(output, '');
    reset(input);
    rewrite(output);

    while (not eof) do
    begin
        readln(buf);
        if (buf = '#') then break;

        ans := 0;
        for i:=1 to length(buf) do
        begin
            if (buf[i] = ' ') then value := 0
            else value := ord(buf[i]) - 65 + 1;

            ans := ans + i * value;
        end;

        writeln(ans);
    end;

    close(input);
    close(output);
end.
